package me.hys.api.doctor;

import java.util.List;

import me.hys.api.BaseApi;
import me.hys.base.ApiResult;
import me.hys.base.PageQuery;
import me.hys.bo.doctor.DoctorBo;
import me.hys.bo.doctor.DoctorNearBo;
import me.hys.entity.doctor.DoctorInfoEntity;
import me.hys.service.doctor.IDoctorManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: @author HYS . <br>
 * Date: 2015-9-22 下午10:30:53 . <br>
 * Function: 医生接口
 */
@Controller
@RequestMapping("/api/doctor")
public class DoctorApi extends BaseApi {
	@Autowired
	private IDoctorManager doctorManager;

	/**
	 * @Title : list
	 * @Description : 医生列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/{start}", method = RequestMethod.GET)
	public List<DoctorBo> list(@PathVariable int start) {
		PageQuery<DoctorBo> page = getPageQuery(start);
		page.getCondition().put("userId", request.getParameter("userId"));
		PageQuery<DoctorBo> result = doctorManager.findPageBo(page);
		return result.getList();
	}

	/**
	 * @Title : list
	 * @Description : 医生列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/{userId}/{start}", method = RequestMethod.GET)
	public List<DoctorBo> list(@PathVariable int userId, @PathVariable int start) {
		PageQuery<DoctorBo> page = getPageQuery(start);
		page.getCondition().put("userId", userId);
		PageQuery<DoctorBo> result = doctorManager.findPageBo(page);
		return result.getList();
	}

	/**
	 * @Title : list
	 * @Description : 附近的医生列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/near/{longitude}/{latitude}/{start}", method = RequestMethod.GET)
	public List<DoctorNearBo> near(@PathVariable double longitude,
			@PathVariable double latitude, @PathVariable int start) {
		PageQuery<DoctorNearBo> page = getPageQuery(start);
		page.getCondition().put("longitude", longitude);
		page.getCondition().put("latitude", latitude);
		PageQuery<DoctorNearBo> result = doctorManager.findNearPageBo(page);
		return result.getList();
	}

	/**
	 * @Title : list
	 * @Description : 医生在线列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/online/{start}", method = RequestMethod.GET)
	public List<DoctorBo> online(@PathVariable int start) {
		PageQuery<DoctorBo> page = getPageQuery(start);
		page.getCondition().put("online", "online");
		PageQuery<DoctorBo> result = doctorManager.findPageBo(page);
		return result.getList();
	}

	/**
	 * @Title : post
	 * @Description : 登陆后发送自己状态
	 */
	@ResponseBody
	@RequestMapping(value = "/post/status", method = RequestMethod.POST)
	public ApiResult post(@ModelAttribute DoctorInfoEntity entity) {
		return doctorManager.doctorInfo(entity);
	}

	/**
	 * @Title : post
	 * @Description : 登陆后发送自己状态
	 */
	@ResponseBody
	@RequestMapping(value = "/post/status_test", method = RequestMethod.GET)
	public ApiResult test(@ModelAttribute DoctorInfoEntity entity) {
		return doctorManager.doctorInfo(entity);
	}
}
